<?php
namespace Kuoqi\Api\Sms;
use \Kuoqi\Curl;
/**
 * 短信模块的相关信息
 * Class Sms
 * @package Kuoqi\Api
 */
class Smsbao extends \Kuoqi\Api\Sms{

    protected $_url = 'http://api.smsbao.com/sms';
    protected $_params =array(
        'u'=>'',
        'p'=>'',
        'm'=>'',
        'c'=>'',
    );
    protected $_username = '';//短信宝用户名
    protected $_passowrd = '';//短信宝密码
    /**
     * 初始化
     * Email constructor.
     */
    public function __construct()
    {

    }

    public function setUsername($username){
        $this->_username = $username;
    }

    public function setPassword($password){
        $this->_passowrd = $password;
    }

    protected function analysis()
    {
        if(!$this->_username){
            $this->is_valied = 0;
            $this->errmsg = '请调用方法[$this->setUsername($username)]填写短信宝的账号，参考地址为：http://api.smsbao.com/';
            return;
        }
        if(!$this->_passowrd){
            $this->is_valied = 0;
            $this->errmsg = '请调用方法[$this->setPassword($password)]填写短信宝的密码，参考地址为：http://api.smsbao.com/';
            return;
        }
        $this->_params['u'] = $this->_username;
        $this->_params['p'] = $this->_passowrd;
        $this->_params['m'] = $this->_tel;
        $this->_params['c'] = $this->_text;
    }

    /**
     * 重构发送方法
     * createby kuoqi at 2022/10/19 14:28
     * @return mixed
     */
    public function send(){
        $this->analysis();
        if($this->isValied()){
            $curres = Curl::sendTo($this->_url,'GET',$this->_params,'string');
            if($curres === '0'){
                $this->is_valied = 1;
                $this->errmsg = '短信发送成功';
            }else{
                $this->is_valied = 0;
                $this->errmsg = '短信发送失败';
            }
        }
        return $this->isValied();
    }
}